package com.redoop.common;

import org.apache.log4j.PropertyConfigurator;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class IniFile {
	/** 配置文件路径 */
	private String conf_path;
	/** LOG文件相对路径 */
	private String log4j_path;
	/** Mybatis文件相对路径 */
	private String mybatis_path;

	private String read_path;

	private String jdbc_path;

	String absolute = Thread.currentThread().getContextClassLoader().getResource("").getPath();

	/**
	 * 读取配置文件
	 * @param path 配置文件相对路径
	 * @return
	 */
	public boolean readConfigFile(String path){
		boolean ret_val = true;
		try {
			// 服务器WEB绝对路径
			FileInputStream fis = new FileInputStream(path);
			Properties prop = new Properties();
			prop.load(fis);
			fis.close();
			fis = null;
			conf_path = path;
			log4j_path = prop.getProperty("log4j.path","log4j.properties");
			PropertyConfigurator.configure(absolute+log4j_path);
			mybatis_path = prop.getProperty("mybatis.path","mybatis-config.xml");
			read_path = prop.getProperty("read.path","oracle.txt");
			jdbc_path = prop.getProperty("jdbc.path","jdbc.properties");
			prop = null;
		} catch (IOException e) {
			ret_val = false;
			e.printStackTrace();
		}
		
		return ret_val;
	}

	public String getConf_path() {
		return conf_path;
	}

	public String getRead_path() {
		return absolute+read_path;
	}

	public String getJdbc_path() {
		return absolute+jdbc_path;
	}

	public String getLog4j_path() {
		return absolute+log4j_path;
	}

	public String getMybatis_path() {
		return absolute+mybatis_path;
	}


	
}
